|
|
|
|
|
|
|
Puzzle 11
Registry Games, Part 1 |
|
|
|
|
|
|
|
|
Reading the system registry is one of the most common tasks that Visual Basic programmers attemptand one of the most frustrating. The registry is a hierarchical database that looks something like a file system. File system directories correspond to registry keys. Files in a file system correspond to the values for the keys. Figure P11-1 shows a typical display from the Windows registry editor. On Windows NT 4.0, the registry has five visible roots, each of which is identified by a constant value. The highlighted entry has the following registry path: |
|
|
|
|
|
|
|
|
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control |
|
|
|
|
|
|
|
|
The right pane of the figure shows that this key has three named values: CurrentUser, SystemStartOptions, and WaitToKillServiceTimeout. A key can also have a default value that does not have a name. The data type of the value appears immediately after the namein this case, all three values are of type REG_SZ (text data). The value data follows the data type. |
|
|
|
|
|
|
|
|
Figure P11-1:
A typical display from the Windows registry editor |
|
|
|
|
|
|
|
|
Your mission (should you choose to accept it) is to write a short program that enumerates all of the keys under this key and displays the values for each key. To keep things simple, the example will only look at keys that appear under the Control keyit will not scan deeper into the hierarchy. That exercise is left for the reader. |
|
|
|
|
|
|
|
|
Because there are many pitfalls to reading the registry, this task is divided into several puzzles. But don't think for a minute that I am doing this just to make the examples easier to follow. This actually reflects a strategy I always use when undertaking API-based tasks: It's always best to code and test small portions of the application and eliminate bugs as you find them. That way, you gain understanding of the API subsystem |
|
|
|
|
|